﻿using System;

using CodingBlog.Core.ExtensionMethods;
using CodingBlog.Core.Model;
using CodingBlog.Core.Repository;
using CodingBlog.Core.Repository.Contract;

namespace CodingBlog.Core.Service
{
    internal class UserService
    {
        private IUserRepository userRepository;

        public UserService()
        {
            this.userRepository = new UserRepository();
        }

        public UserService(IUserRepository userRepository)
        {
            this.userRepository = userRepository;
        }

        public User CreateUser(User user)
        {
            user.Password = user.Password.ComputeHash();

            return userRepository.CreateUser(user);
        }

        public User GetUserById(int userId)
        {
            return userRepository.GetUserById(userId);
        }

        public bool EmailIsInUse(string emailToCheck)
        {
            return userRepository.EmailIsInUse(emailToCheck);
        }

        public User ValidateUser(string email, string password)
        {
            return userRepository.GetUserByEmailAndPassword(email, password.ComputeHash());
        }
    }
}